import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:flutter_study/project/_02douban/model/home_model.dart';

import 'config.dart';
import 'http_utils.dart';

class HomeRequest {
  static Future<List<MovieItem>> getMovieList(int start) async {
    final movieUrl = "/movie/top250?start=$start&count=${HomeConfig.pageSize}";

    final result = await HttpUtils.request(movieUrl);
    print('result = $result');
    List<MovieItem> movieList = [];
    return movieList;
  }

  // 豆瓣开放api已关闭，使用本地json代替
  static Future<List<MovieItem>> getMovieListByFile(int start) async {
    final result = await rootBundle.loadString("assets/douban.json");
    final resultJson = json.decode(result);
    final subjects = resultJson["subjects"];
    List<MovieItem> movieList = [];
    for (var subject in subjects) {
      movieList.add(MovieItem.fromMap(subject));
    }
    return movieList;
  }
}
